//
//  DDDAdZYSdkRewardVideoVC.m
//  DDDAdZYSdkDemo
//
//  Created by mu on 2020/9/14.
//  Copyright © 2020 summer. All rights reserved.
//

#import "DDDAdZYSdkRewardVideoVC.h"
#import <DDDAdZYSdk/DDDAdZYSdk.h>

@interface DDDAdZYSdkRewardVideoVC ()<DDDAdZYRewardVideoAdDelegate>
@property (nonatomic, strong) DDDAdZYRewardVideoAd *rewardVideoAd;

@property (nonatomic, strong) UIButton *palyBtn;
@end

@implementation DDDAdZYSdkRewardVideoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"激励视频";
    [self.view addSubview:self.palyBtn];
    [self configLoadData];
}

- (void)configLoadData {
    if (!self.rewardVideoAd) {
        DDDAdZYRewardVideoAd *rewardVideoAd = [[DDDAdZYRewardVideoAd alloc]initWithRewardVideoAdId:@"ZY65509201136114201" andUserId:@"aaa"];
        rewardVideoAd.delegate = self;
        [rewardVideoAd loadAd];
        self.rewardVideoAd = rewardVideoAd;
    } else {
        [self.rewardVideoAd loadAd];
    }
    
}

#pragma mark-- 点击事件
- (void)clickBtnAction:(UIButton *)sender {
    if (self.rewardVideoAd.adValid) {
        [self.rewardVideoAd showAdFromRootViewController:self];
    }
    
}

#pragma mark-- DDDAdZYRewardVideoAdDelegate
/**
 视频广告素材加载成功回调
 */
- (void)nativeExpressRewardedVideoAdDidLoad:(DDDAdZYRewardVideoAd *)rewardedVideoAd {
    NSLog(@"%s",__func__);
}

/**
 视频广告缓存成功回调
 */
- (void)nativeExpressRewardedVideoAdDidDownLoadVideo:(DDDAdZYRewardVideoAd *)rewardedVideoAd {
    NSLog(@"%s",__func__);
}



/**
 视频广告将要显示时调用
 */
- (void)nativeExpressRewardedVideoAdWillVisible:(DDDAdZYRewardVideoAd *)rewardedVideoAd {
    NSLog(@"%s",__func__);
}

/**
 视频广告显示时调用
 */
- (void)nativeExpressRewardedVideoAdDidVisible:(DDDAdZYRewardVideoAd *)rewardedVideoAd {
    NSLog(@"%s",__func__);
}


/**
 视频广告关闭时回调
 */
- (void)nativeExpressRewardedVideoAdDidClose:(DDDAdZYRewardVideoAd *)rewardedVideoAd {
    NSLog(@"%s",__func__);
    [self configLoadData];
}

/**
 点击视频广告时回调
 */
- (void)nativeExpressRewardedVideoAdDidClick:(DDDAdZYRewardVideoAd *)rewardedVideoAd {
    NSLog(@"%s",__func__);
}


/**
 视频播放出现错误
 @param errorCode : 错误码
 */
- (void)nativeExpressRewardedVideoAdDidPlayDidFailWithError:(NSInteger)errorCode {
    NSLog(@"%s--%ld",__func__,errorCode);
}

//视频播放结束
- (void)nativeExpressRewardedVideoAdDidPlayFinish:(DDDAdZYRewardVideoAd *)rewardedVideoAd {
    NSLog(@"%s",__func__);
}
#pragma mark-- 懒加载
- (UIButton *)palyBtn {
    if (!_palyBtn) {
        _palyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _palyBtn.frame = CGRectMake(15.0, 100.0, [UIScreen mainScreen].bounds.size.width - 30.0, 45.0);
        [_palyBtn setTitle:@"播放" forState:UIControlStateNormal];
        [_palyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _palyBtn.backgroundColor = [UIColor redColor];
        [_palyBtn addTarget:self action:@selector(clickBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        _palyBtn.tag = 10;
    }
    return _palyBtn;
}
@end
